local lizha = fk.CreateSkill {
  name = "th_lizha",
  derived_piles = "$th_mamizou_ye",
  tags = { Skill.Compulsory }
}

---@type fun(self: TriggerSkill, event: TurnEvent, target: ServerPlayer, player: ServerPlayer, data: TurnData)
local use_spec = function(self, event, target, player, data)
  local room = player.room
  local cards = room:getNCards(3, "bottom")
  local result = room:askToChooseCardsAndChoice(player, {
    cards = cards,
    choices = {"OK"},
    skill_name = lizha.name,
    prompt = "#th_lizha-discard",
    min_num = 1,
    max_num = 1,
  })
  local card = Fk:getCardById(result[1])
  if not card.is_passive and (card.type == Card.TypeBasic or card:isCommonTrick()) then
    player:addToPile("$th_mamizou_ye", card, false, lizha.name, player)
  else
    room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, lizha.name, nil, true, player)
  end
end

lizha:addEffect(fk.TurnEnd, {
  on_use = use_spec
})

lizha:addEffect(fk.CardUseFinished, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(lizha.name) and player.phase ~= Player.Play and data.card and data.card.type ~= Card.TypeBasic
  end,
  on_use = use_spec
})

Fk:loadTranslationTable{
  ["th_lizha"] = "狸诈",
  [":th_lizha"] = "锁定技，结束阶段，或当你于出牌阶段外使用非基本牌后，你观看牌堆底的三张牌并弃置其中一张牌，若此牌为指定角色为目标的基本牌或普通锦囊牌，改为将之扣置于你的武将牌上，称为“叶”。",

  ["#th_lizha-discard"] = "狸诈：请弃置其中一张牌",

  ["$th_mamizou_ye"] = "叶",
}

return lizha
